package file;

import java.io.BufferedReader;
import java.io.FileReader;

/**
 * @time: 2019/11/27 17:49
 * @author: baozi
 * 缓冲流
 * 用缓存的————》数组提高效率
 */
public class BufferedStream {

    public static void main(String[] args) {

        try {
            //字节缓存输出流
            /*BufferedOutputStream b=new BufferedOutputStream(new FileOutputStream("a.txt"));
            b.write("我写出去的".getBytes());
            b.close();*/

            //字节缓存输入流
            //BufferedInputStream b=new BufferedInputStream(new FileInputStream("a.txt"));
            /*int i;
            while((i=b.read())!=-1){
                System.out.print((char)i);
            }*/
            /*byte[] a=new byte[1024];
            while(b.read(a)!=-1){
                System.out.print(new String(a));
            }
            b.close();*/

            //文件复制
            /*BufferedInputStream  c=new BufferedInputStream(new FileInputStream("1.jpg"));
            BufferedOutputStream b=new BufferedOutputStream(new FileOutputStream("22.jpg"));
            long start=System.currentTimeMillis();
            int i;
            while((i=c.read())!=-1){
                b.write(i);
            }
            System.out.println("时间"+(System.currentTimeMillis()-start));
            b.close();
            c.close();*/

            //字符缓冲输入/输出流
            /*BufferedWriter w=new BufferedWriter(new FileWriter("1.txt",true));
            for(int i=0;i<=2;i++){
                w.newLine();//换行
                w.write("我是包子");
            }
            w.close();*/

            BufferedReader r = new BufferedReader(new FileReader("1.txt"));
            String str = r.readLine();//读取一行，不读取换行符
            if(str!=null){
                System.out.println(str);
            }
            r.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
